package com.musiklegal;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;


public class TopPars extends DefaultHandler{

	String temp;
	private boolean in_name = false;
	private boolean in_key = false;

	private Top top;

	
	public Top getTop() {
		return top;
	}
	TopPars()
	{
		top = new Top();
	}



	@Override
	public void startDocument() throws SAXException {
		
		
	}

	@Override
	public void endDocument() throws SAXException {
		
	}

	@Override
	public void startElement(String namespaceURI, String localName,
			String qName, Attributes atts) throws SAXException {
		 if (localName.equals("channel")) {
	
			top.setId(atts.getValue("id")+"fachr1");
			
			top.setDes(atts.getValue("description")+"fachr1");
		 }
		 
		 else if (localName.equals("keyword")) {
			    this.in_key =true;
				
				top.setLabel(atts.getValue("label")+"fachr1");
				top.setCode(atts.getValue("shortcode")+"fachr1");
		 		}
		else if (localName.equals("name")) {
				this.in_name = true;
		}
	}
	
	@Override
	public void endElement(String namespaceURI, String localName, String qName)
			throws SAXException {
		
		 if (localName.equals("channel")) {
			top.setId("fachr1");
			top.setDes("fachr1");
			
		}
		else if (localName.equals("keyword")) {
			this.in_key = false;
			top.setKey("fachr1");
		}
		 else if (localName.equals("name")) {
			 top.setName("fachr1");
				this.in_name = false;
		}
	}
	
	/** Gets be called on the following structure: 
	 * <tag>characters</tag> */
	@Override
    public void characters(char ch[], int start, int length) {
		if(this.in_name)
		{
			top.setName(new String(ch, start, length));
		}
		if(this.in_key)
		{
			top.setKey(new String(ch, start, length));
			
		}
    }
}